:: Monad m => String -> m a -package:universum
Fail with a message. This operation is not part of the mathematical
definition of a monad, but is invoked on pattern-match failure in a
do expression.
As part of the MonadFail proposal (MFP), this function is moved to its
own class
MonadFail (see
Control.Monad.Fail for more
details). The definition here will be removed in a future release.
throws
ExpectFailed. This is nice for writing your own
abstractions.
Throw an error, escaping the current computation up to the nearest
catchError (if any).
runThrow (throwError e >>= k) = runThrow (throwError e)
Like
throwEnvelopeErr but without providing a message.
>>> import Control.Monad.Except (runExcept)
>>> throwEnvelopeErr "BAD_ERROR" "a very bad error occurred!" :: Either (Err String) Int
Left (Err {errErr = "BAD_ERROR", errExtra = Just "a very bad error occurred!"})
A higher-order generalisation of
replicate. For example
foo :: IO (String, String, String)
foo = replicateT getLine
> foo
Hello
world
!
("Hello","world","!")
A higher-order generalisation of
sequenceA. For example
> sequenceT (print 3110, putStrLn World) :: IO ((), ())
3110
World
((),())
A convenience function for throwing a user error. This is useful for
cases where it would be too high a burden to define your own exception
type.
This throws an exception of type
StringException. When GHC
supports it (base 4.9 and GHC 8.0 and onward), it includes a call
stack.
Lifted version of
die.
>>> die "Goodbye!"
Goodbye!
*** Exception: ExitFailure 1
When you encounter an error where the only sane way to handle it is to
write an error to the log and die messily, use fatalError. This is a
good candidate for things like not being able to find configuration
files on startup.